package com.google.demo.Activity;

import java.util.ArrayList;
import java.util.List;

import com.google.demo.R;
import com.google.demo.AsyncTask.LoadMoreListViewHistory;
import com.google.demo.adapter.HistoryAdapter;
import com.google.demo.model.HistoryItem;
import com.google.demo.model.HistoryItemInfo;

import android.app.ProgressDialog;
import android.content.Context;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

public class HistoryActivity extends MainActivity implements OnClickListener {
	
	private ListView mListView;
	private TextView mLoadMore;
	private HistoryAdapter mAdapter;
	private List<HistoryItem> mHistoryItem;
	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		getTextViewHeader().setText(getString(R.string.histories));
		getmButton_left().setVisibility(View.GONE);
		getmButton_right().setVisibility(View.GONE);
		getLeft_view().setVisibility(View.GONE);
		getRight_view().setVisibility(View.GONE);
		LayoutInflater mLayoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		getFrameLayoutMain().addView(mLayoutInflater.inflate(R.layout.history_layout, null, true));
		
		mHistoryItem = new ArrayList<HistoryItem>();
		mHistoryItem.add(new HistoryItem());
		mHistoryItem.add(new HistoryItem());
		mHistoryItem.add(new HistoryItem());
		mHistoryItem.add(new HistoryItem());
		mHistoryItem.add(new HistoryItem());
		mHistoryItem.add(new HistoryItem());
		mHistoryItem.add(new HistoryItem());
		mHistoryItem.add(new HistoryItem());
		mHistoryItem.add(new HistoryItem());
		
		initControl();
		HistoryAdapter adapter = new HistoryAdapter(HistoryActivity.this,mHistoryItem);
		mListView.setAdapter(adapter);
		
	}
	
	private void initControl(){
		mListView=(ListView)findViewById(R.id.listView_history);
		mLoadMore = new Button(this);
		mLoadMore.setText("Load More");
		mLoadMore.setOnClickListener(this);
		mListView.addFooterView(mLoadMore);
	}

	@Override
	public void onBackPressed() {
		// TODO Auto-generated method stub
		UIBottomButtonsHelper.CURRENT_SCREEN_OF_4_MAINSCREEN = UIBottomButtonsHelper.SCAN_SCREEN;
		super.onBackPressed();
		
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		if(v == mLoadMore){
			Log.d("-------Datpv---onClick", "load more 2");
			new LoadMoreListViewHistory(HistoryActivity.this,mListView,mHistoryItem).execute();
		}
	}
		
}
